home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 5.4 KB | 262 lines | [TEXT/CWIE] |
- //============================================================================
- // CFileItem.cp ©1997 Metrowerks Inc. All rights reserved
- // Original author: John C. Daub
- //============================================================================
- // A concrete LOutlineItem for items of type "file"
-
-
- #include "CFileItem.h"
- #include "SendFinderOpen.h"
- #include <LOutlineItem.h>
- #include <LOutlineTable.h>
- #include <UGAColorRamp.h>
- #include "OutlineTablePrefix.h"
- #include <Gestalt.h>
- #include <LString.h>
- #include <TextUtils.h>
-
- #include "GetFileIcon.h"
-
- extern Handle gOnIcon;
- extern Handle gOffIcon;
-
- StringPtr gGestaltBitNames[] =
- {
- "\pDrag Manager Present",
- "\pDrag Manager Floating Window",
- "\pPPC Drag Lib Present",
- "\pDrag Manager Has Image Support",
- "\pCan Start Drag in Float Window"
- };
-
- // constructor
-
- CFileItem::CFileItem(
- int nameId,
- OSType selector,
- int bit
- )
- {
- OSErr err = noErr;
- long response = 0;
-
- fNameId = nameId;
- fSelector = selector;
- fBit = bit;
-
- err = Gestalt(selector, &response);
-
- if (err == noErr)
- {
- fState = ((response & (1L << bit)) ? true : false);
- }
- else
- {
- fState = true;
- }
-
- }
-
-
- // dtor
-
- CFileItem::~CFileItem()
- {
- }
-
- // this is the routine called to know what to draw within the
- // table cell. See the comments in LOutlineItem.cp for more info.
-
- void
- CFileItem::GetDrawContentsSelf(
- const STableCell& inCell,
- SOutlineDrawContents& ioDrawContents)
- {
- switch (inCell.col)
- {
- default:
- {
- ioDrawContents.outShowSelection = true;
- ioDrawContents.outHasIcon = true;
- ioDrawContents.outIconSuite = (fState? gOnIcon : gOffIcon);
- ioDrawContents.outTextTraits.style = 0;
-
- if (fNameId >= 0)
- {
- LString::CopyPStr(gGestaltBitNames[fNameId], ioDrawContents.outTextString);
- }
- else
- {
- Str255 tmpName;
- Str255 tmpNumber;
-
- LString::FourCharCodeToPStr(fSelector, tmpName);
- NumToString(fBit, tmpNumber);
- LString::AppendPStr(tmpName, tmpNumber);
- LString::CopyPStr(tmpName, ioDrawContents.outTextString);
- }
-
- break;
- }
- }
- }
-
- // just to be cute, we'll draw an adornment (again, see the LOutlineItem.cp
- // comments for more information). We'll draw a groovy gray background
-
- void
- CFileItem::DrawRowAdornments(
- const Rect& inLocalRowRect )
- {
- ShadeRow(UGAColorRamp::GetColor(2), inLocalRowRect);
- }
-
-
- // just to be cute, when a double-click occurs, we'll send the Finder
- // and open document AppleEvent to open our selected item... just to do
- // something.
-
- void
- CFileItem::DoubleClick(
- const STableCell& /* inCell */,
- const SMouseDownEvent& /* inMouseDown */,
- const SOutlineDrawContents& /* inDrawContents */,
- Boolean /* inHitText */)
- {
- // ThrowIfOSErr_(SendFinderOpenAE(&mFileSpec));
- }
-
- // ---------------------------------------------------------------------------
- // * TrackContentClick [protected]
- // ---------------------------------------------------------------------------
- // Called by ClickCell whenever a mouse-down event occurs within
- // the contents (icon or text) of this cell. Selects or deselects this
- // cell as appropriate and tests for dragging or double-clicking.
-
- void
- CFileItem::TrackContentClick(
- const STableCell& /*inCell*/,
- const SMouseDownEvent& inMouseDown,
- const SOutlineDrawContents& /*inDrawContents*/,
- Boolean inHitText)
- {
- inHitText = inHitText;
-
- #if 000000
- // If item isn't selected, try to select it now.
-
- Boolean wasSelected = mOutlineTable->CellIsSelected(inCell);
- if (!wasSelected) {
- if (!(inMouseDown.macEvent.modifiers & shiftKey))
- mOutlineTable->UnselectAllCells();
- mOutlineTable->SelectCell(inCell);
- mOutlineTable->UpdatePort();
- }
- #endif
- // See if mouse moves. If it does, track a drag from it
-
- if (::StillDown() && ::WaitMouseMoved(inMouseDown.macEvent.where)) {
- // TrackDrag(inCell, inMouseDown, inDrawContents);
- return;
- }
-
- #if 000000
- // Mouse didn't move, see if this was a double-click.
-
- if (LPane::GetClickCount() > 1) {
- DoubleClick(inCell, inMouseDown, inDrawContents, inHitText);
- return;
- }
-
- // If none of the above, and shift key was down, deselect this cell.
-
- if (wasSelected && (inMouseDown.macEvent.modifiers & shiftKey)) {
- mOutlineTable->UnselectCell(inCell);
- mOutlineTable->UpdatePort();
- return;
- }
-
- // Simple click and item is still selected, call it a single click.
-
- if (mOutlineTable->CellIsSelected(inCell)) {
- SingleClick(inCell, inMouseDown, inDrawContents, inHitText);
- return;
- }
- #endif
-
- SetState((fState ? false : true));
- return;
- }
-
- void CFileItem::SetState(bool state)
- {
- long result;
- OSType err;
- AppleEvent aeEvent; // Apple event to send
- AppleEvent aeReply; // Unused reply event
- AEDesc descDest; // Addressee for event
- OSType dest = 'SPJ!';
-
- err = Gestalt(fSelector, &result);
-
- fState = state;
-
- if (fState)
- {
- result |= (1L << ((long)fBit));
- }
- else
- {
- result &= ~(1L << ((long)fBit));
- }
-
- err = ::AECreateDesc (typeApplSignature, &dest, sizeof(OSType), &descDest);
-
- err =
- ::AECreateAppleEvent
- (
- 'SPJ!',
- 'SPJ!',
- &descDest,
- kAutoGenerateReturnID,
- kAnyTransactionID,
- &aeEvent
- );
-
- err =
- ::AEPutParamPtr
- (
- &aeEvent,
- keyDirectObject,
- typeType,
- &fSelector,
- sizeof(OSType)
- );
-
- err =
- ::AEPutParamPtr
- (
- &aeEvent,
- 'ARF ',
- typeLongInteger,
- &result,
- sizeof(long)
- );
-
- err =
- ::AESend
- (
- &aeEvent,
- &aeReply,
- kAEWaitReply + kAECanInteract + kAECanSwitchLayer,
- kAENormalPriority,
- kAEDefaultTimeout,
- nil,
- nil
- );
-
- mOutlineTable->Refresh();
-
- return;
- }
-